#!/usr/bin/env bash

. scripts/common.sh
. scripts/help.sh
. scripts/init-dev-env.sh
. scripts/cleanup-dev-env.sh
. scripts/rm-python-cache.sh
. scripts/tests.sh
. scripts/dev-container.sh
. scripts/build-deb.sh
. scripts/build-rpm.sh
. scripts/build-targz.sh
. scripts/create-build-images.sh
. scripts/build-doc.sh
. scripts/build-preferences.sh
. scripts/make-release.sh
. scripts/send-signal.sh
. scripts/travis-cli-container.sh
. scripts/run-ci.sh
. scripts/watch-doc.sh
. scripts/edit-ui.sh


main () {
  case "$1" in
    init-dev-env) init-dev-env ;;
    cleanup-dev-env) cleanup-dev-env ;;
    run) exec ./bin/ulauncher -v --dev $2 ;;
    rm-python-cache) rm-python-cache ;;
    test-mypy) warn-if-not-in-docker && test-mypy ;;
    test-pylint) warn-if-not-in-docker && test-pylint ;;
    test-flake8) warn-if-not-in-docker && test-flake8 ;;
    test-pytest) warn-if-not-in-docker && test-pytest ;;
    test) warn-if-not-in-docker && test-mypy && test-flake8 && test-pylint && test-pytest ;;
    dev-container) dev-container $2 ;;
    send-signal) send-signal $2 ;;
    edit-ui) edit-ui $2 ;;
    build-deb) build-deb $2 $3 ;;
    build-rpm) build-rpm $2 $3 $4 ;;
    build-targz) build-targz $2 ;;
    aur-update) ./scripts/aur-update.py $2 ;;
    create-build-images) create-build-images ;;
    build-doc) build-doc ;;
    build-preferences) build-preferences $2 ;;
    make-release) make-release $2 ;;
    travis-cli-container) travis-cli-container ;;
    run-ci) run-ci ;;
    watch-doc) watch-doc ;;

    *)
      echo "${red}[!] Unrecognized command '${1}'${normal}"
      echo
      help
      exit 1
      ;;
  esac
}

if [ $# -eq 0 ]; then
  help
else
  main $@
fi
